package com.amsp.oa.oademo.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.amsp.oa.oademo.entity.EmployeeAccess;
import com.amsp.oa.oademo.mapper.EmployeeAccessMapper;
import com.amsp.oa.oademo.service.EmployeeAccessService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.List;

@Service
public class EmployeeAccessServiceImpl extends ServiceImpl<EmployeeAccessMapper, EmployeeAccess>
        implements EmployeeAccessService {
    @Override
    public IPage<EmployeeAccess> getPage(Integer current, Integer size, String name, String employeeId, String date) {
        Page<EmployeeAccess> page = new Page<>(current, size);
        LambdaQueryWrapper<EmployeeAccess> wrapper = new LambdaQueryWrapper<>();

        // 添加搜索条件
        if (StringUtils.hasText(name)) {
            wrapper.like(EmployeeAccess::getName, name);
        }
        if (StringUtils.hasText(employeeId)) {
            wrapper.like(EmployeeAccess::getEmployeeId, employeeId);
        }
        if (StringUtils.hasText(date)) {
            wrapper.eq(EmployeeAccess::getDate, date);
        }

        // 按日期和时间倒序排序
        wrapper.orderByDesc(EmployeeAccess::getDate)
                .orderByDesc(EmployeeAccess::getStartTime);
        Page<EmployeeAccess> page1 = this.page(page, wrapper);


        return page1;
    }

    @Override
    public boolean saveBatch(List<EmployeeAccess> records) {
        return super.saveBatch(records);
    }
}